from random import choice

class RandomWalk:
    '''随机游走数据生成类'''

    def __init__(self, num_points=3000) -> None:
        '''初始化方法，确定随机游走点数'''
        self.num_points = num_points

        # 随机游走数据记录, 默认起始于（0，0）
        self.x_vals = [0]
        self.y_vals = [0]

    def fill_walk(self):
        '''计算游走的所有点'''
        while len(self.x_vals) < self.num_points:
            # 决定前进方向,并指定移动距离
            x_direction = choice([-1,1])
            x_distance = choice([0,1,2,3,4])
            x_step = x_direction * x_distance

            y_direction = choice([-1,1])
            y_distance = choice([0,1,2,3,4])
            y_step = y_direction * y_distance

            # 跳过已有的点
            if x_step == 0 and y_step == 0:
                continue

            # 计算下一个点的坐标
            x = self.x_vals[-1] + x_step
            y = self.y_vals[-1] + y_step
            self.x_vals.append(x)
            self.y_vals.append(y)


